package cc.smarnet.caihou.phone.taginfolists;

import android.app.DatePickerDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cc.smarnet.caihou.LoginActivity;
import cc.smarnet.caihou.R;

import cc.smarnet.caihou.entity.Bracts;
import cc.smarnet.caihou.entity.TagInfo;
import okhttp3.Call;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * 入库信息详情的Activity
 */
public class TaginfoListDetailActivity extends AppCompatActivity {
    private ImageButton imageButton;


    private EditText baseNameText;
    private EditText varietyText;
    private EditText varietyCodeText;
    private EditText packingSpecificationsText;
    private EditText classesText;
    private EditText flowerLengthText;
    private EditText stockinTimeText;
    private EditText detailInUserText;
    private EditText detailOutTimeText;
    private EditText detailOutUserText;
    private EditText createTimeText;

    private String token;
    private ProgressBar progressBar;

    TagInfo tagInfo;


    int mYear, mMonth, mDay;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_taginfo_detail);

        getSupportActionBar().hide();//隐藏标题栏

        initViews();
        setDisEnabled();
        getToken();

        tagInfo = (TagInfo) getIntent().getSerializableExtra("taginfoDetail");
        baseNameText.setText(tagInfo.getSourceBase());
        varietyText.setText(tagInfo.getVariety());
        varietyCodeText.setText(tagInfo.getVarietyCode());
        packingSpecificationsText.setText(tagInfo.getPackingSpecifications());
        classesText.setText(tagInfo.getClasses());
        flowerLengthText.setText(tagInfo.getFlowerPoleLength());
        stockinTimeText.setText(tagInfo.getStockInTime());
        detailInUserText.setText(tagInfo.getStockInUser());
        detailOutTimeText.setText(tagInfo.getStockOutTime());
        detailOutUserText.setText(tagInfo.getStockOutUser());
        Date createTime = tagInfo.getCreateTime();
        String createTime2 = null ;
        if(createTime!=null ){
            createTime2 = createTime.toString();
        }
        createTimeText.setText( createTime2 );

        // 点击返回按钮的监听
        imageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    public void initViews() {
        imageButton = findViewById(R.id.bracts_detail_return);

        baseNameText = findViewById(R.id.detail_baseName);
        varietyText = findViewById(R.id.detail_variety);
        varietyCodeText = findViewById(R.id.detail_varietyCode);
        packingSpecificationsText = findViewById(R.id.detail_packing_specifications);
        classesText = findViewById(R.id.detail_classes);
        flowerLengthText = findViewById(R.id.detail_flower_pole_length);
        stockinTimeText = findViewById(R.id.detail_stock_in_time);
        detailInUserText = findViewById(R.id.detail_stock_in_user);
        detailOutTimeText = findViewById(R.id.detail_stock_out_time);
        detailOutUserText = findViewById(R.id.detail_stock_out_user);
        createTimeText = findViewById(R.id.detail_createTime);

        progressBar = findViewById(R.id.bracts_detail_progressBar);
    }

    // 设置各控件不可用
    public void setDisEnabled() {
        baseNameText.setEnabled(false);
        varietyText.setEnabled(false);
        varietyCodeText.setEnabled(false);
        packingSpecificationsText.setEnabled(false);
        classesText.setEnabled(false);
        flowerLengthText.setEnabled(false);
        stockinTimeText.setEnabled(false);
        detailInUserText.setEnabled(false);
        detailOutTimeText.setEnabled(false);
        detailOutUserText.setEnabled(false);
        createTimeText.setEnabled(false);
    }


    public void getToken() {
        SharedPreferences sp = getSharedPreferences("userInfo", MODE_PRIVATE);
        token = sp.getString("token", null);
    }


    // 获取当前日期
    public void getDate() {
        Calendar calendar = Calendar.getInstance();
        mYear = calendar.get(Calendar.YEAR);
        mMonth = calendar.get(Calendar.MONTH);
        mDay = calendar.get(Calendar.DAY_OF_MONTH);
    }

}